package com.didd.core.constant.enums;


import com.didd.core.dict.core.DictEnumInterface;

/**
 * 通用禁用与启用枚举
 *
 * @author diddd
 * @since 2019/12/11
 */
public enum DisableEnum implements DictEnumInterface {
    /**
     * 启用
     */
    ENABLE("0", "启用"),

    /**
     * 禁用
     */
    DISABLE("1", "禁用"),

    /**
     * 未知
     */
    UNKNOWN("-1", "未知");

    private final String code;

    private final String name;

    DisableEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public String getCode() {
        return code;
    }

    public Integer getCodeValue() {
        return Integer.valueOf(code);
    }

    @Override
    public String getName() {
        return name;
    }

    public static DisableEnum getEnum(String code) {
        for (DisableEnum disableEnum : DisableEnum.values()) {
            if (disableEnum.getCode().equals(code)) {
                return disableEnum;
            }
        }
        return UNKNOWN;
    }

    public static DisableEnum getEnum(Integer code) {
        for (DisableEnum disableEnum : DisableEnum.values()) {
            if (disableEnum.getCode().equals(String.valueOf(code))) {
                return disableEnum;
            }
        }
        return UNKNOWN;
    }

    public static String getName(String code) {
        DisableEnum disableEnum = DisableEnum.getEnum(code);
        return disableEnum.getName();
    }


    public static String getName(Integer code) {
        DisableEnum disableEnum = DisableEnum.getEnum(code);
        return disableEnum.getName();
    }
}
